import { Item } from "ant-design-vue/lib/menu";
import { createStore } from "vuex";

const store = createStore({
  state() {
    return {
      isFullScreen: false,
      buycarts: [],
    };
  },
  getters: {
    totalPrice(state) {
      return state.buycarts.reduce((pre, cur) => pre + cur.price * cur.num, 0);
    }
  },
  mutations: {
    setFullScreen(state, payload) {
      state.isFullScreen = payload;
    },
    addBuycarts(state, payload) {
      state.buycarts.push(payload);
    },
    addBuycartsNum(state, payload) {
      state.buycarts[payload].num++;
    },
    minusBuycartsNum(state, payload) {
      state.buycarts[payload].num--;
      if (!state.buycarts[payload].num) {
        state.buycarts.splice(payload, 1);
      }
    },
  },
  actions: {},
});

export default store;
